<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>LineLayer图层</title>
    <style type="text/css">
    body,
    html {
        width: 100%;
        height: 100%;
        margin: 0;
    }
    #allmap {
        height: 100%;
        width: 100%;
    }
    </style>
    <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=MgS1Fax5a4gQ1a6eos6cEx4XN8sxHqSB"></script>
</head>

<body>
    <div id="allmap"></div>
</body>

</html>
<script type="text/javascript">
    var map = new BMapGL.Map('allmap',{
        enableRotate: false,
        enableTilt: false
    });
    var localcity = new BMapGL.LocalCity();
    localcity.get(e => {
        console.log("城市中心：",e.center);
        var point = new BMapGL.Point(e.center.lng, e.center.lat);
        map.centerAndZoom(point, 11);
        map.enableScrollWheelZoom();
    });
    var zoomCtrl = new BMapGL.ZoomControl();  // 添加缩放控件
    map.addControl(zoomCtrl);

    //创建地址解析器实例
    //var myGeo = new BMapGL.Geocoder();
    // 将地址解析结果显示在地图上，并调整地图视野
    /*
    myGeo.getPoint('廊坊市香河县五一公园', function(point){
        if(point){
            map.centerAndZoom(point, 16);
            map.addOverlay(new BMapGL.Marker(point, {title: '北京市海淀区上地10街'}))
        }else{
            alert('您选择的地址没有解析到结果！');
        }
    }, '北京市')

    var geolocation = new BMapGL.Geolocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                var mk = new BMapGL.Marker(r.point);
                map.addOverlay(mk);
                map.panTo(r.point);
                alert('您的位置：' + r.point.lng + ',' + r.point.lat);
            }
            else {
                alert('failed' + this.getStatus());
            }        
        });
        */

        
      
          
/*
          var driving = new BMapGL.DrivingRouteLine(map, { 
            renderOptions: { 
                map: map, 
                autoViewport: false
            },
            onSearchComplete: function(r){
                drawLine(map,r.getPlan(0).getRoute(0).points)
            }
        })
        

        var start = new BMapGL.Point(116.69058173, 39.54336666);
        var end = new BMapGL.Point(117.00018499999993, 39.751019088752415);

        driving.search(start, end);


        function drawLine(map,pintArr){
          console.log("路线1结果：", pintArr)
          var tmpGenJson = {
            type: "FeatureCollection",
            features: [{
              type: "Feature",
              properties: {
                name: "demo1"
              },
              geometry: {
                type: "LineString",
                coordinates: pintArr
              }
            }]
          }
          console.log("路线2结果：", tmpGenJson)
          var lineLayer = new BMapGL.LineLayer({
                  style: {
                      // borderMask: false,
                      borderColor: '#ff0000',
                      borderWeight: 1,
                      strokeWeight: 2,
                      strokeColor: '#ff0000'
                  }
              });
          lineLayer.setData(tmpGenJson);
          map.addNormalLayer(lineLayer);
        }
        */

        var tmpGenJson = {
            type: "FeatureCollection",
            features: [{
              type: "Feature",
              properties: {
                name: "demo1"
              },
              geometry: {
                type: "LineString",
                coordinates: [
                    [116.69056161138,39.543376887037],
                    [116.6901597095,39.54336242003],
                    [116.68871280881,39.543293075732],
                    [116.68863241047,39.543294258133],
                    [116.68822035773,39.543280347533],

                    [116.68660206036,39.543205299799],

                    [116.68637083652,39.543198970469],

                    [116.68636068566,39.54332903462],
                    [116.6862896297,39.544029985743],
                    [116.68623896527,39.544370651811],
                    [116.68615784828,39.545071661879],
                    [116.68612739572,39.545352091728],
                    [116.68611724487,39.545432214333],
                    [116.68610700419,39.545672303383],
                    [116.68609685334,39.545772386608],
                    [116.68605624993,39.546152965823],
                    [116.68599534481,39.546713746019],
                    [116.68592419902,39.547454583694],
                    [116.68589383629,39.547695013434],
                    [116.68588359561,39.547855113998],
                    [116.6858632939,39.548075373375],
                    [116.68580238879,39.548626123056],
                    [116.68579223794,39.548726271533],
                    [116.68576187521,39.548986656891],
                    [116.68575172436,39.549076790055],
                    [116.68573133282,39.549327020241],
                    [116.6857212718,39.549377163535],
                    [116.68569072942,39.549777543558],
                    [116.68565012601,39.550128056726],
                    [116.68563988532,39.550308180855],
                    [116.68562973447,39.550418341479],
                    [116.68556891919,39.550939098408],
                    [116.68551816493,39.551419793615],
                    [116.6854675005,39.551880456704],
                    [116.6854166564,39.552481108337],
                    [116.68537596316,39.552931611008],
                    [116.68535557163,39.553241842763],
                    [116.68534542078,39.553401930424],
                    [116.68534542078,39.553421958742],
                    [116.68533518009,39.553632047093],
                    [116.68532502924,39.553722174173],
                    116.70103639261,39.567458845235
                    116.69673656346,39.598823329603
                    116.69749688924,39.607079546556
                    116.70040641096,39.62138309955
                    116.70055705679,39.621832317176
                    116.70084810778,39.62263091131
                    116.68349392329,39.664236027551
                ]
              }
            }]
          }
          console.log("路线2结果：", tmpGenJson)
          var lineLayer = new BMapGL.LineLayer({
                  style: {
                      // borderMask: false,
                      borderColor: '#ff0000',
                      borderWeight: 1,
                      strokeWeight: 2,
                      strokeColor: '#ff0000'
                  }
              });
          lineLayer.setData(tmpGenJson);
          map.addNormalLayer(lineLayer);
</script>